package com.xunge.controller;

import com.xunge.anno.Log;
import com.xunge.pojo.Exam;
import com.xunge.pojo.ExamQueryParam;
import com.xunge.pojo.PageResult;
import com.xunge.pojo.Result;
import com.xunge.service.ExamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/exam")
@RestController
public class ExamController {
    @Autowired
    private ExamService examService;

    /**
     * 分页查询考试信息
     */
    @GetMapping
    public Result page(ExamQueryParam examQueryParam){
        log.info("分页请求参数:{}" ,examQueryParam);
        PageResult<Exam> pageResult = examService.page(examQueryParam);
        return Result.success(pageResult);
    }

    /**
     * 保存考试
     */
    @Log
    @PostMapping
    public Result save(@RequestBody Exam exam){
        log.info("保存信息：{}",exam);
        examService.save(exam);
        return Result.success();
    }

    /**
     * 批量删除考试
     */
    @Log
    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        log.info("根据ID批量删除考试: {}",ids);
        examService.delete(ids);
        return Result.success();
    }

    /**
     * 根据ID查询考试
     */
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("根据ID查询考试: {}",id);
        Exam exam = examService.getById(id);
        return Result.success(exam);
    }

    /**
     * 根据ID修改考试
     */
    @Log
    @PutMapping
    public Result update(@RequestBody Exam exam){
        log.info("根据ID修改考试：{}",exam);
        examService.update(exam);
        return Result.success();
    }

    /**
     * 根据课程ID查询考试
     */
    @GetMapping("/course/{courseId}")
    public Result getByCourseId(@PathVariable Integer courseId){
        log.info("根据课程ID查询考试: {}",courseId);
        List<Exam> exams = examService.getByCourseId(courseId);
        return Result.success(exams);
    }

    /**
     * 根据班级ID查询考试
     */
    @GetMapping("/clazz/{clazzId}")
    public Result getByClazzId(@PathVariable Integer clazzId){
        log.info("根据班级ID查询考试: {}",clazzId);
        List<Exam> exams = examService.getByClazzId(clazzId);
        return Result.success(exams);
    }
} 